package com.example.demo.web.rest.controller;

import com.example.demo.client.evt.sysbasequery.QueryUrlConfigEvt;
import com.example.demo.client.vm.sysbasequery.UrlConfigVm;
import com.example.demo.domain.UrlConfig;
import com.ffcs.oss.param.out.ServiceResp;
import com.ffcs.oss.param.vm.QueryPageVm;
import com.example.demo.service.UrlConfigService;
import com.example.demo.web.rest.evt.IdEvt;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * URL配置管理
 * @Author zhengmf
 * @Date 2018/12/27  17:57
 */
@Api("URL配置")
@RestController
@RequestMapping("/api/urlConfig")
public class UrlConfigController extends BaseController{
    @Autowired
    private UrlConfigService urlConfigService;

    @ApiOperation("刷新URL配置缓存")
    @PostMapping(value = "/refreshAll")
    public ServiceResp refreshAllUrlConfig(){
        return baseQueryClient.refreshAllUrlConfig();
    }

    @ApiOperation("查询URL配置")
    @PostMapping(value = "/queryUrlConfig")
    public ServiceResp<QueryPageVm<UrlConfigVm>> queryUrlConfig(@RequestBody QueryUrlConfigEvt evt){
        return baseQueryClient.queryUrlConfig(evt);
    }

    @ApiOperation("保存URL配置")
    @PostMapping(value = "/saveUrlConfig")
    public ServiceResp<Boolean> saveUrlConfig(@RequestBody @Validated UrlConfig urlConfig){
        urlConfigService.saveUrlConfig(urlConfig);
        baseQueryClient.refreshAllUrlConfig();
        return ServiceResp.getInstance(Boolean.class).success(true);
    }

    @ApiOperation("根据id删除Url配置，逻辑删除")
    @PostMapping(value = "/delUrlConfigById")
    public ServiceResp<Boolean> delUrlConfigById(@RequestBody @Validated IdEvt evt){
        urlConfigService.updateStatus(evt.getId());
        baseQueryClient.refreshAllUrlConfig();
        return ServiceResp.getInstance(Boolean.class).success(true);
    }

}
